Namespace Data
    Public Class FixedColumnField
        Public Const MIN_COLUMN As Integer = 1
        Public Const INFINITE_LENGTH_MARK As Integer = 0

        Public Name As String
        Public FromColumn As Integer = MIN_COLUMN

        Public Length As Integer = INFINITE_LENGTH_MARK

        Public Sub SetFromColumn(ByVal value As Object)
            Integer.TryParse(value.ToString, FromColumn)
            If FromColumn < MIN_COLUMN Then FromColumn = MIN_COLUMN
        End Sub

        Public Sub SetLength(ByVal value As Object)
            Integer.TryParse(value.ToString, Length)
            If Length < INFINITE_LENGTH_MARK Then Length = INFINITE_LENGTH_MARK
        End Sub

        Public Function Retrieve(ByVal From As String) As String
            If FromColumn > From.Length Then
                Return ""
            ElseIf Length = INFINITE_LENGTH_MARK Then
                Return From.Substring(FromColumn - 1)
            ElseIf FromColumn + Length - 1 >= From.Length Then
                Return From.Substring(FromColumn - 1)
            Else
                Return From.Substring(FromColumn - 1, Length)
            End If
        End Function
    End Class
End Namespace
